package com.ilibrary.base;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

public abstract class MyAjaxAction extends MyBaseAction {
	public final String execute() throws Exception {
		JSONObject result = null;
		
		try{
			result = doExecute(getRQ(), getRP(), getSSN());
		}catch(Exception ex){
/*			logger.fatal("exception -- ",ex);
			if(ex instanceof LoginRedirectException){
				result = new JSONObject();
				result.put("result", SystemConstants.AJAX_FAILED_LOGIN);
				result.put("msg", ErrorMsgConstants.ERR_LOGIN);
			}else if(ex instanceof ServiceException){
				result = new JSONObject();
				result.put("result", SystemConstants.AJAX_FAILED_ALERT);
				result.put("msg",ex.toString());
			}else{
				result = new JSONObject();
				result.put("result", SystemConstants.AJAX_FAILED_ALERT);
				result.put("msg", ErrorMsgConstants.ERR_SYSTEM);
			}*/
			ex.printStackTrace();
		}
		getRP().setContentType("application/json;charset=utf-8");
		getRP().getWriter().write(result.toString());
		return null;
	}
	
	protected abstract JSONObject doExecute(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception;
}
